package interpreter;

/**
 * @author Roderland
 * @since 1.0
 */
public enum Registers {
    EAX(0), // return value
    EBX(0), // callee saved
    ECX(0), // 4th argument
    EDX(0), // 3th argument
    ESI(0), // 2nd argument
    EDI(0), // 1st argument
    EBP(0), // callee saved frame pointer
    ESP(0), // stack pointer
    RIP(0); // program counter

    public static Registers getRegister(String name) {
        switch (name) {
            case "eax": return EAX;
            case "ebx": return EBX;
            case "ecx": return ECX;
            case "edx": return EDX;
            case "esi": return ESI;
            case "edi": return EDI;
            case "ebp": return EBP;
            case "esp": return ESP;
            case "rip": return RIP;
        }
        return null;
    }

    private int value;

    Registers(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public int getValueW() {
        return value & 0x0000ffff;
    }

    public void setValueW(int value) {
        this.value = (this.value & 0xffff0000) | (value & 0x0000ffff);
    }

    public int getValueB() {
        return value & 0x000000ff;
    }

    public void setValueB(int value) {
        this.value = (this.value & 0xffffff00) | (value & 0x000000ff);
    }
}
